<template>
  <a-card style="margin:0;border-radius:0px">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="处理时间">
              <j-date style="width: 100%" v-model="model.clDate"
                      :disabled="(stage == '05010' || stage == '05050') ? true:(bgStatus === '9' || bgStatus === '2' || bgStatus == '3'?true:false)"></j-date>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="12">
            <a-form-item label="处理意见">
              <a-textarea
                v-model="model.clComit"
                :auto-size="{ minRows: 3, maxRows: 3 }"
                :disabled="(stage == '05010' || stage == '05050') ? true:(bgStatus === '9' || bgStatus === '2' || bgStatus == '3'?true:false)"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table-operator" v-if="stage !== '05010' && stage !== '05050'">
      <a-button :disabled="bgStatus === '9' || bgStatus === '2' || bgStatus == '3'"
                type="primary"
                @click="saveData">保存
      </a-button>
      <a-button :disabled="bgStatus === '9' || bgStatus === '2' || bgStatus == '3'"
                v-permission="['30010']"
                type="primary"
                @click="showConfirm">
        提交审核
      </a-button>
      <a-button :disabled="bgStatus !== '2'"
                v-permission="['30020']"
                @click="setApproveReason('9')">
        同意
      </a-button>
      <a-button :disabled="bgStatus !== '2'"
                v-permission="['30020']"
                type="danger"
                @click="setApproveReason('1')">
        拒绝
      </a-button>
    </div>
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="false"
      :loading="loading"
    >
      <span slot="actionName">
        <a-upload v-if="stage !== '05010' && stage !== '05050'"
                  :disabled="bgStatus == '9' || bgStatus == '2'"
                  v-permission="['30010']" accept=".docx, .doc, .xlsx, .xls, .pdf, .jpeg, .png"
                  :data="fileData" name="files" :showUploadList="false" :multiple="false" :headers="tokenHeader"
                  :action="url.upLoad" @change="handleImportExcel">
          <a-button
            size="small"
            type="primary"
            icon="import">上传</a-button>
        </a-upload>
        <span v-else>操作</span>
      </span>
      <span slot="action" slot-scope="text, record">
        <a @click="OnPerview(record)">预览</a>
        <a-divider type="vertical"/>
        <a @click="OnDownLoad(record)">下载</a>
      </span>
    </a-table>
    <SelectApprove ref='approver' :id='id' @submitData='handleSubmit'></SelectApprove>
    <SetReason ref='setReason' @approveReason='approveData'></SetReason>
  </a-card>
</template>

<script>
  import {filePerviewMixin} from '@/mixins/filePerviewMixin'
  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import {BgPubFun} from '../bgPubFun'
  import {getAction, postAction} from '@/api/manage'
  import SelectApprove from '../public/SelectApprover'
  import SetReason from "../public/SetReason"
  import columns from './indexColumns'

  export default {
    name: "clyj",
    mixins: [JeecgListMixin, filePerviewMixin, BgPubFun],
    components: {
      SelectApprove,
      SetReason
    },
    props: ['id', 'stage'],
    data() {
      return {
        queryParam: {
          id: this.id
        },
        model: {
          fileId: ''
        },
        fileData: {
          biz: 'baogao_clyj',
          type: 'baogao_clyj',
          proId: this.id
        },
        bgStatus: '',
        approveStatus: '',
        typeId: '103',
        bgType: 'baogao_clyj',
        //表头
        columns: columns(this),
        url: {
          save: '/sjxmzygl/sjWorkBaogaoClyj/save',
          saveBg: '/sjxmzygl/sjWorkBaogao/saveBg',
          submit: '/sjxmzygl/sjWorkUsers/submitAudit',
          yjData: '/sjxmzygl/sjWorkBaogaoClyj/queryById',
          approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
          list: '/sjxmzygl/sjWorkBaogao/queryAuditReportInfo',
          upLoad: `${window._CONFIG['domianURL']}/sys/common/sjBgUpload`
        }
      }
    },
    created() {
      this.getYjData()
    },
    methods: {
      handleImportExcel(info) {
        if (info.file.status === 'done') {
          if (info.file.response.success) {
            this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
            this.model.fileId = info.file.response.result[0].id
            this.saveBg(info.file.response.result[0].id, this.bgType)
          } else {
            this.$message.error(`${info.file.name} ${info.file.response.message}.`);
          }
        } else if (info.file.status === 'error') {
          this.$message.error(`文件上传失败: ${info.file.msg} `);
        }
      },
      saveData() {
        postAction(this.url.save, {
          proId: this.id,
          fileId: this.fileId,
          type: 'baogao_clyj ',
          ...this.model
        }).then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData()
          } else {
            this.$message.error(res.message)
          }
        })
      },
      loadData() {
        this.loading = true
        this.dataSource = []
        getAction(this.url.list, this.queryParam).then((res) => {
          if (res.success) {
            this.bgStatus = res.result.clyj.status
            if (res.result.clyj.id != undefined) {
              this.model.fileId = res.result.clyj.id
              this.dataSource.push(res.result.clyj)
            }
          } else {
            this.$message.error(res.message)
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false;
        })
      },
      getYjData() {
        getAction(this.url.yjData, this.queryParam).then((res) => {
          if (res.success) {
            if (res.result != '未找到对应数据') {
              this.model = res.result
            }
          } else {
            this.$message.error(res.message)
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      }
    }
  }
</script>

<style scoped>
  .table-page-search-wrapper {
    height: 88px
  }
</style>